package cn.turingbyte.FileIO;

import java.io.*;

public class VincentVic20200107 {
    public static void main(String[] args) {
        //testFileWR();
        //testFileWRStream();
        try {
            FileInputStream fileInputStream = new FileInputStream("vincent.vic");
            InputStreamReader inputStreamReader = new InputStreamReader(fileInputStream);
            BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
            String a;
            while((a = bufferedReader.readLine())!=null){
                System.out.println(a);
            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public static void testFileWRStream() {
        try {
            FileOutputStream outputStream = new FileOutputStream("vincent.vic");
            outputStream.write("Vincent Vic".getBytes());
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        try {
            FileInputStream outputStream = new FileInputStream("vincent.vic");
            int n=0;
            while ((n=outputStream.read())!=-1){
                System.out.print((char)n);
            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public static void testFileWR() {
        try {
            FileWriter writer = new FileWriter("vincent.vic");
            for (int i = 97; i < 122; i++) {
                writer.write(i);
            }
            writer.write("Vincent Vic");
            writer.close();
        } catch (IOException e) {
            e.printStackTrace();
        }

        try {
            FileReader reader = new FileReader("vincent.vic");
            int n=0;
            while ((n=reader.read())!=-1){
                System.out.print((char)n);
            }
            reader.close();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
